<html>
	<head>
		<meta charset="utf-8">
		<title>批量添加 - 1对1镜像</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
	</head>
	<body>
<div class="layui-layui-fluid"> 
	<div class="layui-row">
		<div class="layui-col-xs10">
			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="text" value="格式：“指定域名|目标站点|指定资料夹”，一行一条，支持多条。" class="layui-input layui-font-blue" readonly>
				</div>
			</div>
			<form class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">批量添加:</label>
					<div class="layui-input-block">
						<textarea type="text" name="hownew" lay-verify="required" placeholder="格式说明：以 ‘ | ’ 符合隔开。" class="layui-textarea"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button type="submit" class="layui-btn" lay-submit lay-filter="howadd">添加</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<script src="../../res/layui/layui.js"></script>
<script>
layui.use(['form','layer'], function(){
  var form = layui.form;
  var layer = layui.layer;
  // 批量添加
  form.on('submit(howadd)', function(data){
    var field = data.field; // 获取表单字段值
    var hownew = field.hownew;
		hownew = hownew.replace(/\+/g,"%2B"); //转义+号正常输出
		hownew = hownew.replace(/\&/g,"%26"); //转义&号正常输出
		var xmlhttp = new XMLHttpRequest(); // 创建一个新的XMLHttpRequest对象
		xmlhttp.onreadystatechange = function() {  //回调函数
		 if (this.readyState == 4 && this.status == 200) { //回调成功做判断
			 if(this.responseText){
			   layer.msg('存在以下相同站点：不能重复添加' + '<br>' + this.responseText);
				 parent.layui.table.reloadData('demo');   //刷新父级数据表格，仅数据重载			
			   }else{
					layer.msg('添加成功');
					parent.layui.table.reloadData('demo');   //刷新父级数据表格，仅数据重载	
				 	setTimeout(function(){
						var index = parent.layer.getFrameIndex(window.name); //获取当前页面索引
						parent.layer.close(index);//关闭open
				 },1500); //设置延时1.5秒关闭			
				}
			}
		};
		xmlhttp.open("POST", "../make.php",true); // 发送POST请求，将数据传递给服务器端PHP脚本
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send("hownew=" + hownew);
    return false; // 阻止默认 form 跳转
  });

});
</script>
</body>
</html>